home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / tktdoc / porting.doc < prev    next >
Encoding:
Text File  |  1994-08-11  |  9.3 KB  |  209 lines

  1. PORTING APPLICATIONS FROM UNIX TO DESQVIEW/X
  2.  
  3. This chapter gives guidelines and helpful hints for porting UNIX X  Window
  4. clients from UNIX to the DESQview/X DOS environment. It provides an
  5. overview of porting issues, the preparation of files for the DOS environment
  6. and traps related to the porting process.
  7.  
  8. The basic porting strategy is to:
  9.  
  10. - copy the source files to your DOS machine and resolve
  11.   file naming conflicts,
  12. - substitute header file #includes,
  13. - write a makefile for your program,
  14. - work around or remove unix specific code,
  15. - resolve compiler differences,
  16. - make your program and
  17. - run and debug your program.
  18.  
  19. The strategy is straight forward and it can sometimes be extremely
  20. easy to port programs from UNIX to DESQview/X.
  21.  
  22. Copy Source Files
  23.  
  24. You can use FTP or the DESQview/X File Manager to transfer files from
  25. other machines across the network.
  26.  
  27. Part of the process of getting the files onto your machine is to resolve
  28. file names to DOS eight character names with three character extensions
  29. (i.e., NNNNNNNN.EEE). If you were to just get all of the files without
  30. resolving the names first, your files that have more than eight character
  31. names will get truncated to eight character names. This might work
  32. out to be okay as long as they got truncated uniquely to an eight
  33. character names. This is often not the case and you will need to resolve
  34. the conflict by renaming the applicable files on the UNIX machine
  35. prior to your copying them over.
  36.  
  37. It can sometimes be convenient to do all of the filename resolution
  38. on the other end and then zip the files and just copy over one zip
  39. file, then unzip it on your DOS machine. When using FTP or fileman
  40. to copy a zipped file make sure to copy the files in binary mode.
  41. If you do not, the zip file will be corrupt. During this process,
  42. keep a list of all of the header files names that you changed. It
  43. will be used in the next step.
  44.  
  45. Substitute Header File #include Names
  46.  
  47. Once you have your source files copied over uniquely you will need
  48. to resolve the #include header file names within your source. This
  49. process is made easier by the use of the utility UNIX2DVX.EXE.
  50.  
  51. Put all of your source and header files in the current directory.
  52. Copy the UNIX2DVX.TXT file into your current directory. This file
  53. contains header file name substitutions for X and Motif. Edit your
  54. private copy to include your own header file name substitutions.
  55.  
  56. Do C:MYPORT> UNIX2DVX *.C PORTC.LIS
  57.  
  58. This will make the header file name substitutions within an #ifdef
  59. MSDOS construct. This way the substitution will only be made if MSDOS
  60. is defined. Review the PORTC.LIS file for substitutions that were
  61. not made because they were already within an #ifdef construct.   You
  62. will have to make these substitutions manually using an editor.
  63.  
  64. See the WRAPPER.TXT file. UNIX2DVX.EXE uses it to get the substitution
  65. format. You may customize it for yourself if you wish.
  66.  
  67. Repeat this process for the header files (i.e., C:\MYPORT> UNIX2DVX
  68. *.H PORTH.LIS).
  69.  
  70. Write a Makefile For Your Program
  71.  
  72. Identify what sources get linked into your program and write a makefile.
  73. It is sometimes easy to clone an existing makefile out of the DEMOS
  74. or CLIENTS directory.
  75.  
  76. Copy one that uses the model that you want (ie. HCLE, WC4G or MAKEFILE).
  77.  
  78. Work Around or Remove UNIX Specific Code
  79.  
  80. When making any changes to source, it is best to #ifdef MSDOS the
  81. changes. This way the things that you did to accomplish the port are
  82. documented and the source will still compile on its original platform.
  83.  
  84. Work around or remove UNIX specific code. Notable functions that are
  85. missing from DOS compilers are signal(), fork(), exec() and pipes.
  86.  
  87. The DESQview/X system library routine that is used to start another
  88. process is pif_start(). See Chapter 9: The DESQview/X System
  89. Library.
  90.  
  91. Change '/'s in file path names to '\\' since DOS uses '\' as the path
  92. delimiter. The reason that you need two backslashes is because the
  93. first backslash is used as the literal character. Many DOS compiler
  94. functions will accept forward slashes as directory delimiters. The
  95. fopen() function is one of these. Check it with your particular compiler.
  96.  
  97. Some UNIX programs refer to files in /usr/... . There is not a /usr
  98. directory in the default DESQview/X installation.
  99.  
  100. Some UNIX programs look for the /TMP directory, it is not there by
  101. default. It can be helpful to define a TEMP environment variable to
  102. point to where your temp directory is and get it with a getenv() at
  103. runtime.
  104.  
  105. Bitmaps are kept in \DVX\INCLUDE\X11\BITMAPS instead of
  106. /USR/X11/INCLUDE/BITMAPS.
  107.  
  108. In UNIX you can read() and write() to a Berkeley socket. This does
  109. not work under DOS. Change your read()s to recv()s and your write()s
  110. to send()s. A trick that you can use in the routine that does the
  111. read() and write() is to make a #define macro that replaces write(args)
  112. with send(args) and read(args) with recv(args). Just be careful only
  113. to define it for the routines that use it in this way.
  114.  
  115. If you are reading a binary file that was generated on another platform,
  116. you have to be cognizant of what the byte ordering and structure alignment
  117. were on that platform and accommodate accordingly.
  118.  
  119. For instance, on a Sparc platform the byte ordering is MSB or big-endian
  120. and on the PC the byte ordering is LSB or little-endian. If you were
  121. reading a binary file generated on the Sparc that had IEEE 32-bit
  122. floating point numbers or 32 bit integers then you would need to byte
  123. swap the data before your application used it. For 32 bit numbers,
  124. you would swap byte 1 with byte 4 and byte 2 with byte 3.
  125.  
  126. If you are reading a binary file that was generated by writing out
  127. structures, you have to be aware of what the structure alignment and
  128. padding policy was for the compiler that was used to compile the program
  129. that generated the binary file. You cannot necessarily just use the
  130. same structure definition on another platform and just read the binary
  131. data into the structure.
  132.  
  133. Resolve Compiler Differences
  134.  
  135. DOS compilers are often times more particular than are the UNIX cc
  136. compilers. Often code that compiles code fine with cc will not compile
  137. with DOS compilers. Some common things that cause code not to immediately
  138. compile are duplicate defined functions, structures or #defines, function
  139. arguments that do not match the function prototype or the use of common
  140. macro defines that happen not to be defined for your compiler environment.
  141.  
  142. Your code may generate many compiler warnings, such as the ones that
  143. you may see in the demos and clients that came with the toolkit. Many
  144. of the warnings are harmless and you can ignore them. However, for
  145. a real world deliverable application, it would be most prudent to
  146. examine each of the warnings carefully and eliminate them if possible.
  147.  
  148. It is always good to prototype your own functions. It does not take
  149. much time to do it and it can sometimes point out a nasty bug immediately
  150. which otherwise would have been difficult to find.
  151.  
  152. Build Your Program
  153.  
  154. If everything was done 100 percent correctly and you planned for every
  155. contingency then your program should compile and link the first time.  It
  156. does happen that way sometimes.
  157.  
  158. Build your program by doing
  159.  
  160. C:\MYPORT> qmake -x -f "makefile name"
  161.  
  162. You may find some errors in your makefile or some unresolved externals
  163. at link time. You will need to deal with the unresolved externals
  164. on a case by case basis.
  165.  
  166. Once you get your program to link then you can go on to running and
  167. debugging it.
  168.  
  169. Running and Debugging Your Program
  170.  
  171. Before running your program make sure that your environment is set
  172. up properly for your program. Sometimes programs use environment variables
  173. at runtime by calling getenv(). Make sure that any data files that
  174. the program uses are available and in the right places.
  175.  
  176. If your program crashes upon startup, check the trouble shooting section
  177. in Appendix A for tips. Sometimes something simple like not
  178. having a large enough stack can cause a crash.
  179.  
  180. Once obvious things have been eliminated,  make a debug version of
  181. your program, see where it crashes and take it from there. Some useful
  182. tools or tricks in helping you debug your program are:
  183.  
  184. XSync() can be called to force synchronous execution,
  185. ensuring that all events are processed as they occur. This is particularly
  186. useful at the toolkit level. Also see XSynchronize() and XFlush in
  187. the Xlib reference manual.
  188.  
  189. Display your program remotely on another server,  maybe
  190. the one on the platform from which you ported it. This could help
  191. identify a server problem. Applications should be tested on as many
  192. different servers as possible. Anomalies that occur on one server
  193. may disappear on another, meaning that a server inconsistency has
  194. caused the problem.
  195.  
  196. For obscure bugs, running without a window manager
  197. can serve to further isolate the problem.
  198.  
  199. Private error handlers can be written to trap particular
  200. errors. The private error handler can print out a diagnostic and continue
  201. program execution.
  202.  
  203. Some  problems in porting X Clients arise from the nature of the X
  204. Window System itself, especially if it is new to you. Event driven
  205. programming, the network model, layers of libraries and their interdependency,
  206. all contribute to the complexity with which you must deal. Working
  207. through a successful port will go far in providing the expertise needed
  208. for new development.
  209.